/**
 * Copyright(C) 2012 Luvina
 * FullNameValidator.java, 10-06-2012 NguyenVietDung
 */
package net.luvina.manageuser.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import net.luvina.manageuser.util.Message;

/**
 * Description
 *
 * @author NguyenVietDung
 */
public class FullNameValidator implements Validator {

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * javax.faces.validator.Validator#validate(javax.faces.context.FacesContext
	 * , javax.faces.component.UIComponent, java.lang.Object)
	 */
	@Override
	public void validate(FacesContext context, UIComponent component, Object str) throws ValidatorException {
		FacesMessage message = new FacesMessage();
		String labelField = (String) component.getAttributes().get("label");
		String value = String.valueOf(str);
		if (value.length() >= 255) {
			StringBuilder msgStr = new StringBuilder();
			msgStr.append("255 桁以内の ");
			msgStr.append(" 「").append(labelField).append("」 ").append(Message.getString("ER006_fullName"));
			message.setDetail(msgStr.toString());
			message.setSummary(msgStr.toString());
			throw new ValidatorException(message);
		}
	}

}
